package system.security.entity;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@Entity
@Table(name="se_role")
@PrimaryKeyJoinColumn(name="id")
public class Role extends Resource {
	
//	protected Set<ResourceType> resourceTypes;
	
	protected Set<Authority> authorities = new HashSet<Authority>();

	public Role(){
		super();
		resourceType = new ResourceType("Role");
	}
	

	@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.LAZY)
	@JoinTable(name = "se_role_authority", 
				joinColumns = { @JoinColumn(name = "role_id") }, 
				inverseJoinColumns = { @JoinColumn(name = "authority_id") })
	public Set<Authority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Set<Authority> authorities) {
		this.authorities = authorities;
	}
	
}
